﻿<avalondock:DocumentContent x:Class="BOL.Apps.GeneNetworkBrowser.Controls.SubNetworksDocument"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:graphsharp="clr-namespace:GraphSharp.Controls;assembly=GraphSharp.Controls"
             xmlns:graphsharpConverters="clr-namespace:GraphSharp.Converters;assembly=GraphSharp.Controls"
             xmlns:avalondock="clr-namespace:AvalonDock;assembly=AvalonDock"
             xmlns:control="clr-namespace:BOL.Apps.GeneNetworkBrowser.Controls"
             xmlns:converters="clr-namespace:BOL.Apps.GeneNetworkBrowser.Converters"
             Title="{Binding Path=Title}"
             >
    <avalondock:DocumentContent.Resources>
        <converters:NameValueMultiBindingConverter x:Key="SelectAllConverter" />
        <graphsharpConverters:EdgeRouteToPathConverter x:Key="EdgeRouteToPathConverter" />
        
        <SolidColorBrush x:Key="HighlightedVertexBorderBrush" Color="Transparent" />
        <SolidColorBrush x:Key="HighlightedVertexBackgroundBrush" Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
        <SolidColorBrush x:Key="HighlightedVertexForegroundBrush" Color="{DynamicResource {x:Static SystemColors.ControlLightLightColorKey}}" />
        <SolidColorBrush x:Key="SemiHighlightedSourceVertexBorderBrush" Color="Transparent" />
        <SolidColorBrush x:Key="SemiHighlightedSourceVertexBackgroundBrush" Color="#FF1DBA00" />
        <SolidColorBrush x:Key="SemiHighlightedTargetVertexBorderBrush" Color="Transparent" />
        <SolidColorBrush x:Key="SemiHighlightedTargetVertexBackgroundBrush" Color="#FFD6A51C" />
        <SolidColorBrush x:Key="HighlightedEdgeBrush" Color="{DynamicResource {x:Static SystemColors.HighlightColorKey}}" />
        <SolidColorBrush x:Key="SemiHighlightedInEdgeBrush" Color="#FF1DBA00" />
        <SolidColorBrush x:Key="SemiHighlightedOutEdgeBrush" Color="#FFD6A51C" />
        
        <Style TargetType="{x:Type graphsharp:VertexControl}">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <TextBlock Text="{Binding Path=FullName}"/>
                </Setter.Value>
            </Setter>

            <Setter Property="Background" Value="#FFE3E3E3" />
            <Setter Property="BorderThickness" Value="1" />
            <Setter Property="Padding" Value="5" />
            <Setter Property="BorderBrush" Value="#FF393939" />
            
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type graphsharp:VertexControl}">
                        <Grid>
                            <Ellipse Opacity="0.8" x:Name="ellipse" Fill="{TemplateBinding Background}" Stroke="{TemplateBinding BorderBrush}" StrokeThickness="{TemplateBinding BorderThickness}" />
                            <ContentPresenter Margin="3" Content="{TemplateBinding Vertex}"/>
                        </Grid>

                        <ControlTemplate.Triggers>
                            <Trigger Property="graphsharp:GraphElementBehaviour.IsHighlighted" Value="True">
                                <Setter Property="BorderBrush" Value="{StaticResource HighlightedVertexBorderBrush}"/>
                                <Setter Property="Background" Value="{StaticResource HighlightedVertexBackgroundBrush}"/>
                                <Setter Property="Foreground" Value="{StaticResource HighlightedVertexForegroundBrush}"/>
                            </Trigger>
                            <Trigger Property="graphsharp:GraphElementBehaviour.IsSemiHighlighted" Value="True">
                                <Setter Property="BorderBrush" Value="{StaticResource HighlightedVertexBorderBrush}"/>
                                <Setter Property="Background" Value="{StaticResource HighlightedVertexBackgroundBrush}"/>
                                <Setter Property="Foreground" Value="{StaticResource HighlightedVertexForegroundBrush}"/>
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="graphsharp:GraphElementBehaviour.IsSemiHighlighted" Value="True"/>
                                    <Condition Property="graphsharp:GraphElementBehaviour.SemiHighlightInfo" Value="Source"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="BorderBrush" Value="{StaticResource SemiHighlightedSourceVertexBorderBrush}"/>
                                <Setter Property="Background" Value="{StaticResource SemiHighlightedSourceVertexBackgroundBrush}"/>
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="graphsharp:GraphElementBehaviour.IsSemiHighlighted" Value="True"/>
                                    <Condition Property="graphsharp:GraphElementBehaviour.SemiHighlightInfo" Value="Target"/>
                                </MultiTrigger.Conditions>
                                <Setter Property="BorderBrush" Value="{StaticResource SemiHighlightedTargetVertexBorderBrush}"/>
                                <Setter Property="Background" Value="{StaticResource SemiHighlightedSourceVertexBackgroundBrush}"/>
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <Style TargetType="{x:Type graphsharp:EdgeControl}">
            <Setter Property="ToolTip">
                <Setter.Value>
                    <TextBlock Text="{Binding Path=RelationTypes}"/>
                </Setter.Value>
            </Setter>

            <Setter Property="MinWidth" Value="1" />
            <Setter Property="MinHeight" Value="1" />
            <Setter Property="Foreground" Value="#FFDDDDDD" />
            <Setter Property="Opacity" Value="0.8" />
            
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="{x:Type graphsharp:EdgeControl}">
                        <Canvas>
                            <Path
                                Stroke="{TemplateBinding Foreground}" 
                                StrokeThickness="{TemplateBinding StrokeThickness}" 
                                MinWidth="{TemplateBinding MinWidth}" 
                                MinHeight="{TemplateBinding MinHeight}" 
                                Opacity="{TemplateBinding Opacity}"
                                x:Name="edgePath"
                                >
                                <Path.Data>
                                    <PathGeometry>
                                        <PathGeometry.Figures>
                                            <MultiBinding Converter="{StaticResource EdgeRouteToPathConverter}">
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Source.(graphsharp:GraphCanvas.X)" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Source.(graphsharp:GraphCanvas.Y)" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Source.ActualWidth" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Source.ActualHeight" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Target.(graphsharp:GraphCanvas.X)" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Target.(graphsharp:GraphCanvas.Y)" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Target.ActualWidth" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="Target.ActualHeight" />
                                                <Binding RelativeSource="{RelativeSource TemplatedParent}" Path="RoutePoints" />
                                            </MultiBinding>
                                        </PathGeometry.Figures>
                                    </PathGeometry>
                                </Path.Data>
                            </Path>
                            <!--<control:EdgeContentPresenter Content="{TemplateBinding Edge}" MouseLeftButtonDown="Edge_MouseLeftButtonDown" />-->
                        </Canvas>
                        
                        <ControlTemplate.Triggers>
                            <Trigger Property="graphsharp:GraphElementBehaviour.IsHighlighted" Value="True">
                                <Setter Property="Foreground" Value="{DynamicResource HighlightedEdgeBrush}" />
                            </Trigger>
                            <Trigger Property="graphsharp:GraphElementBehaviour.IsSemiHighlighted" Value="True">
                                <Setter Property="Foreground" Value="{DynamicResource HighlightedEdgeBrush}" />
                            </Trigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="graphsharp:GraphElementBehaviour.IsSemiHighlighted" Value="True" />
                                    <Condition Property="graphsharp:GraphElementBehaviour.SemiHighlightInfo" Value="InEdge" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Foreground" Value="{DynamicResource SemiHighlightedInEdgeBrush}" />
                            </MultiTrigger>
                            <MultiTrigger>
                                <MultiTrigger.Conditions>
                                    <Condition Property="graphsharp:GraphElementBehaviour.IsSemiHighlighted" Value="True" />
                                    <Condition Property="graphsharp:GraphElementBehaviour.SemiHighlightInfo" Value="OutEdge" />
                                </MultiTrigger.Conditions>
                                <Setter Property="Foreground" Value="{DynamicResource SemiHighlightedInEdgeBrush}" />
                            </MultiTrigger>
                        </ControlTemplate.Triggers>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>

        <CollectionViewSource x:Key="SubNetworkGroups" Source="{Binding Path=SubNetworks}">
            <CollectionViewSource.GroupDescriptions>
                <PropertyGroupDescription PropertyName="VertexCount" />
            </CollectionViewSource.GroupDescriptions>
        </CollectionViewSource>

        <GroupStyle x:Key="NetworkGroupStyle">
            <GroupStyle.HeaderTemplate>
                <DataTemplate>
                    <TextBlock x:Name="_grpVertexCount" FontWeight="Bold" Margin="1" Padding="4" />
                    <DataTemplate.Triggers>
                        <DataTrigger Binding="{Binding Path=VertexCount}" Value="True">
                            <Setter TargetName="_grpVertexCount" Property="Text" Value="{Binding Path=VertexCount}" />
                        </DataTrigger>
                    </DataTemplate.Triggers>
                </DataTemplate>
            </GroupStyle.HeaderTemplate>
        </GroupStyle>

        <Style x:Key="NetworkItemStyle" TargetType="{x:Type ListViewItem}">
            <Setter Property="HorizontalContentAlignment" Value="Stretch" />
            <Setter Property="IsSelected" Value="{Binding Path=IsSelected, Mode=OneWay}" />
            <Style.Triggers>
                <MultiTrigger>
                    <MultiTrigger.Conditions>
                        <Condition Property="ItemsControl.AlternationIndex" Value="1" />
                        <Condition Property="IsSelected" Value="False" />
                        <Condition Property="IsMouseOver" Value="False" />
                    </MultiTrigger.Conditions>
                    <Setter Property="Background" Value="#EEEEEEEE" />
                </MultiTrigger>
            </Style.Triggers>
        </Style>
    </avalondock:DocumentContent.Resources>

    <DockPanel>
        <ToolBarPanel DockPanel.Dock="Top" Background="#FFBCC7D8" Height="26" Orientation="Horizontal">
            <Button Content="Cox" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Height="22" Margin="0,2,0,2" Click="ApplyCox" />
            <Button Content="Expression" Style="{StaticResource {x:Static ToolBar.ButtonStyleKey}}" Height="22" Margin="0,2,0,2" Click="ApplyExpression" />
        </ToolBarPanel>

        <ListView x:Name="lvNetwork" AlternationCount="2" ItemContainerStyle="{StaticResource NetworkItemStyle}" ItemsSource="{Binding SubNetworks}" >
            <ListView.GroupStyle>
                <StaticResourceExtension ResourceKey="NetworkGroupStyle"  />
            </ListView.GroupStyle>

            <ListView.View>
                <GridView>
                    <GridViewColumn>
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <CheckBox Name="_cbSubNetwork" Tag="{Binding Name}"/>
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                        <Grid>
                            <CheckBox x:Name="_cbSelectAll" Tag="AllSubNetworks" ToolTip="Select All" />
                            <!--<CheckBox x:Name="_cbSelectAll" Tag="AllSubNetworks" Command="{Binding SelectAllCheckedCommand}" ToolTip="Select All">
                            <MultiBinding Converter="{StaticResource SelectAllConverter}">
                                <Binding Path="Tag" RelativeSource="{RelativeSource self}" />
                                <Binding Path="IsChecked" RelativeSource="{RelativeSource self}" />
                            </MultiBinding>
                        </CheckBox>-->
                        </Grid>
                    </GridViewColumn>
                    <GridViewColumn Header="Sub-network" Width="400" x:Name="gvcNetwork">
                        <GridViewColumn.CellTemplate>
                            <DataTemplate>
                                <!--<Viewbox Stretch="Uniform" StretchDirection="Both">-->
                                <control:NetworkGraphLayout x:Name="_networkGraphLayout" Graph="{Binding}" LayoutAlgorithmType="CompoundFDP" HighlightAlgorithmType="Simple" />
                                <!--</Viewbox>-->
                            </DataTemplate>
                        </GridViewColumn.CellTemplate>
                    </GridViewColumn>
                    <GridViewColumn Header="#Nodes" DisplayMemberBinding="{Binding Path=VertexCount}" />
                    <GridViewColumn Header="#Edges" DisplayMemberBinding="{Binding Path=EdgeCount}" />
                    <GridViewColumn Header="Cox score" DisplayMemberBinding="{Binding Path=AvgCoxScore}" />
                </GridView>
            </ListView.View>
        </ListView>
    </DockPanel>
</avalondock:DocumentContent>